package com.yycwxt.modules.admin.goodspack;

import com.yycwxt.common.ReturnResult;
import com.yycwxt.domain.GoodsPack;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@Api
@RestController
@Validated
@RequestMapping("/goodspacks")
public class GoodsPackController {
    private GoodsPackService goodsPackService;
    @Autowired
    public GoodsPackController ( GoodsPackService goodsPackService) {
        this.goodsPackService = goodsPackService;
    }
    @GetMapping()
    @ApiOperation("查询全部商品包装")
    public ReturnResult selectAll(){
        return ReturnResult.buildSuccessResult(goodsPackService.list());
    }
    @GetMapping("/{id}")
    @ApiOperation("查询商品包装")
    public ReturnResult getById(@PathVariable Integer id){
        return ReturnResult.buildSuccessResult(goodsPackService.getById(id));
    }
    @PostMapping()
    @ApiOperation("新增商品包装")
    public ReturnResult addGoodsPack(@ApiParam(name = "goodspack对象",required = true,type = "goodspack")@RequestBody@Validated GoodsPack goodsPack){
        return  ReturnResult.buildSuccessResult(goodsPackService.save(goodsPack));
    }
    @DeleteMapping("/{id}")
    @ApiOperation("根据id删除goodspack")
    public ReturnResult deleteGoodsPack(@ApiParam(name = "id",required = true,type = "int")@PathVariable Integer id){
        return ReturnResult.buildSuccessResult(goodsPackService.removeById(id));
    }
    @PutMapping()
    @ApiOperation("根据id修改goodspack")
    public ReturnResult updateGoodsPack(@Validated @ApiParam(name = "goodspack对象",required = true,type = "goodspack")@RequestBody GoodsPack goodsPack){
        return  ReturnResult.buildSuccessResult(goodsPackService.updateById(goodsPack));
    }
}













